<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>快速测试关键 DBC 文件</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        .test-result { margin: 10px 0; padding: 10px; border-radius: 5px; }
        .success { background: #d4edda; border-left: 4px solid #28a745; }
        .failure { background: #f8d7da; border-left: 4px solid #dc3545; }
        .testing { background: #fff3cd; border-left: 4px solid #ffc107; }
        .progress { margin: 20px 0; font-weight: bold; }
        .error-detail { font-size: 0.9em; color: #666; margin-top: 5px; }
    </style>
</head>
<body>
    <h1>快速测试关键 DBC 文件</h1>
    
    <div class="progress" id="progress">准备测试...</div>
    
    <div id="results"></div>

    <script src="dbc-parser.js"></script>
    <script>
        // 选择一些代表性的文件进行快速测试
        const testFiles = [
            'acura_ilx_2016_nidec.dbc',
            'cadillac_ct6_object.dbc',
            'bmw_e9x_e8x.dbc',
            'toyota_2017_ref_pt.dbc',
            'ford_lincoln_base_pt.dbc',
            'tesla_model3_vehicle.dbc',
            'hyundai_kia_generic.dbc',
            'vw_meb.dbc',
            'mazda_2017.dbc'
        ];

        let currentIndex = 0;
        const results = [];

        async function testFile(filename) {
            try {
                const response = await fetch(`../opendbc/opendbc/dbc/${filename}`);
                if (!response.ok) {
                    throw new Error(`HTTP ${response.status}: ${response.statusText}`);
                }

                const content = await response.text();
                const startTime = performance.now();
                const database = parseDBCContent(content, filename);
                const endTime = performance.now();

                return {
                    filename,
                    status: 'success',
                    size: `${(content.length / 1024).toFixed(1)}KB`,
                    parseTime: Math.round(endTime - startTime),
                    frames: database.frames.length,
                    warnings: database.warnings.length
                };
            } catch (error) {
                return {
                    filename,
                    status: 'failure',
                    error: error.message,
                    errorType: categorizeError(error.message)
                };
            }
        }

        function categorizeError(errorMessage) {
            if (errorMessage.includes('VAL_TABLE_')) return 'VAL_TABLE_语法错误';
            if (errorMessage.includes('意外的令牌')) return '语法解析错误';
            if (errorMessage.includes('期望')) return '语法期望错误';
            if (errorMessage.includes('HTTP')) return '文件加载错误';
            return '其他错误';
        }

        function updateProgress() {
            const progressEl = document.getElementById('progress');
            progressEl.textContent = `测试进度: ${currentIndex}/${testFiles.length}`;
        }

        function displayResult(result) {
            const resultsEl = document.getElementById('results');
            const className = result.status;
            
            let statusText = '';
            let errorDetail = '';
            
            if (result.status === 'success') {
                statusText = `✓ 成功 (${result.parseTime}ms, ${result.frames}帧, ${result.warnings}警告)`;
            } else {
                statusText = `✗ 失败 (${result.errorType})`;
                errorDetail = `<div class="error-detail">${result.error}</div>`;
            }

            const resultHtml = `
                <div class="test-result ${className}">
                    <strong>${result.filename}</strong> ${result.size || ''} - ${statusText}
                    ${errorDetail}
                </div>
            `;

            resultsEl.innerHTML += resultHtml;
        }

        async function runTests() {
            for (const filename of testFiles) {
                updateProgress();
                
                const result = await testFile(filename);
                results.push(result);
                displayResult(result);
                
                currentIndex++;
                
                // 给UI一些时间更新
                await new Promise(resolve => setTimeout(resolve, 100));
            }

            updateProgress();
            
            // 显示总结
            const successCount = results.filter(r => r.status === 'success').length;
            const failureCount = results.filter(r => r.status === 'failure').length;
            
            const summaryHtml = `
                <div class="test-result" style="background: #e9ecef; border: none; margin-top: 20px;">
                    <h3>测试总结</h3>
                    <p>总计: ${testFiles.length} 个文件</p>
                    <p>成功: ${successCount} 个文件</p>
                    <p>失败: ${failureCount} 个文件</p>
                    <p>成功率: ${Math.round((successCount / testFiles.length) * 100)}%</p>
                    
                    <h4>失败文件的错误类型:</h4>
                    ${results.filter(r => r.status === 'failure').map(r => 
                        `<div>• ${r.filename}: ${r.errorType}</div>`
                    ).join('')}
                </div>
            `;
            
            document.getElementById('results').innerHTML += summaryHtml;
            document.getElementById('progress').textContent = '测试完成！';
        }

        // 启动测试
        runTests();
    </script>
</body>
</html> 